package com.okaixz.manager.controller;

import com.okaixz.common.annotation.Anonymous;
import com.okaixz.common.annotation.Log;
import com.okaixz.common.client.Result;
import com.okaixz.common.core.controller.BaseController;
import com.okaixz.common.core.domain.AjaxResult;
import com.okaixz.common.core.page.TableDataInfo;
import com.okaixz.common.enums.BusinessType;
import com.okaixz.common.utils.poi.ExcelUtil;
import com.okaixz.manager.domain.KbAssistantTab;
import com.okaixz.manager.service.IKbAssistantTabService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 标签管理Controller
 *
 * @author cdz
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/manager/kbTab")
@Anonymous
public class KbAssistantTabController extends BaseController
{
    @Autowired
    private IKbAssistantTabService kbAssistantTabService;

    /**
     * 查询标签管理列表
     */
    @PreAuthorize("@ss.hasPermi('manager:kbTab:list')")
    @GetMapping("/list")
    public TableDataInfo list(KbAssistantTab kbAssistantTab)
    {
        startPage();
        List<KbAssistantTab> list = kbAssistantTabService.selectKbAssistantTabList(kbAssistantTab);
        return getDataTable(list);
    }
    /**
     * 查询标签列表 parentId不传时查询所有二级标签
     */
    @GetMapping({"/sublist/{parentId}","/sublist"})
    public Result<List<KbAssistantTab>> list(@PathVariable(name = "parentId",required = false) Integer parentId)
    {
        List<KbAssistantTab> list = kbAssistantTabService.selectKbAssistantTabList(parentId);
        return Result.success(list);
    }

    /**
     * 导出标签管理列表
     */
    @PreAuthorize("@ss.hasPermi('manager:kbTab:export')")
    @Log(title = "标签管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KbAssistantTab kbAssistantTab)
    {
        List<KbAssistantTab> list = kbAssistantTabService.selectKbAssistantTabList(kbAssistantTab);
        ExcelUtil<KbAssistantTab> util = new ExcelUtil<KbAssistantTab>(KbAssistantTab.class);
        util.exportExcel(response, list, "标签管理数据");
    }

    /**
     * 获取标签管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:kbTab:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(kbAssistantTabService.selectKbAssistantTabById(id));
    }

    /**
     * 新增标签管理
     */
    @PreAuthorize("@ss.hasPermi('manager:kbTab:add')")
    @Log(title = "标签管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KbAssistantTab kbAssistantTab)
    {
        return toAjax(kbAssistantTabService.insertKbAssistantTab(kbAssistantTab));
    }

    /**
     * 修改标签管理
     */
    @PreAuthorize("@ss.hasPermi('manager:kbTab:edit')")
    @Log(title = "标签管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KbAssistantTab kbAssistantTab)
    {
        return toAjax(kbAssistantTabService.updateKbAssistantTab(kbAssistantTab));
    }

    /**
     * 删除标签管理
     */
    @PreAuthorize("@ss.hasPermi('manager:kbTab:remove')")
    @Log(title = "标签管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(kbAssistantTabService.deleteKbAssistantTabByIds(ids));
    }
}
